# Maintainer: Oleg Tolmatcev <oleg.tolmatcev@gmail.com>

_realname=qpdf
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=9.0.2
pkgrel=1
pkgdesc="QPDF is a program that does structural, content-preserving transformations on PDF files (mingw-w64)"
arch=('any')
url="http://qpdf.sourceforge.net/"
license=("custom:Artistic-2.0")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-libjpeg"
         "${MINGW_PACKAGE_PREFIX}-pcre"
         "${MINGW_PACKAGE_PREFIX}-zlib")
source=("https://sourceforge.net/projects/${_realname}/files/${_realname}/${pkgver}/${_realname}-${pkgver}.tar.gz"
        "0001-fix-printf-on-mingw-w64.patch"
        "0002-enable-advapi32-mingw.patch"
        "0003-install-rule.patch")
sha256sums=('d02451d906068947f45e5216032f0f29ae53313c70c4deedcf3c3e173584d22c'
            '1a3f4afe4e95c58a358fe9f7a062c19ae688d48e1015c67e082978d128a555e9'
            'da1b6cf0464800b70b716579c228800859a5026a7c5d8a2d6caaa01310b2546c'
            'fed969a980f20101611c032d86d56bfd5ffc394a328cc6a8df36e30a410ba6d7')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/0001-fix-printf-on-mingw-w64.patch"
  patch -p1 -i "${srcdir}/0002-enable-advapi32-mingw.patch"
  patch -p1 -i "${srcdir}/0003-install-rule.patch"

  ./autogen.sh
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  cp -rf ${_realname}-${pkgver} build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  ./configure \
      --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST} \
      --target=${MINGW_CHOST} \
      --disable-test-compare-images \
      --enable-external-libs \
      --with-windows-wordsize=${MINGW_PREFIX: -2} \
      --with-buildrules=mingw
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install
}
